package asteroids;

import java.awt.Point;
import java.util.Random;

import com.uqbar.vainilla.DeltaState;

public abstract class Asteroid extends AsteroidsComponent{
	
	final private int MAXSPEED = 25;
	private double speed;
	
	public Asteroid(double x,double y) {
		super(x,y);
	}
	
	@Override
	public void update(DeltaState deltaState) {
		double advanced = this.speed * deltaState.getDelta();
		this.move(advanced*this.getVector().getX(),advanced*this.getVector().getY());
		this.checkScreenLimits();
		super.update(deltaState);
	}
	
	public void initMove(Asteroid ba) {
		Point v = ba.getVector();
		Random r = new Random();
		int rx = r.nextInt(5);
		int ry = r.nextInt(5);
		int x;
		int y;
		if(v.getX()>0)
			x = (int)v.getX()+rx;
		else
			x = (int)v.getX()-rx;
		if(v.getY()>0)
			y = (int)v.getY()+ry;
		else
			y = (int)v.getY()-ry;
		
		this.setVector(new Point(x,y));
		this.setSpeed(r.nextInt(this.getMAXSPEED()));
	}

	public abstract void shooted();
	
	public double getSpeed() {
		return speed;
	}
	
	public void setSpeed(double speed) {
		this.speed = speed;
	}
	
	public int getMAXSPEED() {
		return MAXSPEED;
	}

}
